package com.doge.walknovel.business.home.discover.viewholders

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.wnpro.R
import com.doge.walknovel.api.model.NovelInfo
import com.doge.walknovel.business.home.discover.BOOK_CLICKED
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.wnpro.databinding.CellDiscoverGridRankBinding
import com.doge.walknovel.utils.*

class DiscoverGridRankViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellDiscoverGridRankBinding = CellDiscoverGridRankBinding.inflate(
        LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        itemView.setOnClickCallback { callback.invoke(BOOK_CLICKED, itemView.tag) }
        binding.item.setOnClickCallback { callback.invoke(BOOK_CLICKED, itemView.tag) }
    }

    fun bind(item: NovelInfo, position: Int) {
        itemView.tag = item
        binding.cover.load(item.coverUrl, R.drawable.shape_f7f7f7_8, transformation = RoundedCorners8,  width = 100.dp, height = 143.dp,)
        binding.name.text = item.title
        binding.author.text = item.author
        binding.rank.setImageResource(
            when (position) {
                0 -> R.mipmap.discover_rank1
                1 -> R.mipmap.discover_rank2
                2 -> R.mipmap.discover_rank3
                else -> android.R.color.transparent
            }
        )
    }
}